package org.csmzxy.class2333;

import java.util.TreeSet;
class Student1 implements Comparable<Student1>{
    private String name;
    private int age;
    public Student1(String name,int age){
        this.name = name;
        this.age = age;
    }
    @Override
    public String toString() {
        return "姓名："+name+",年龄："+age;
    }
    @Override
    public int compareTo(Student1 s) {
        int result = this.age - s.age;
        result = result == 0 ? this.name.compareTo(s.name) : result;
        return result;
    }
}
public class Example11 {
    public static void main(String[] args){
        TreeSet<Student1> set = new TreeSet<>();
        set.add(new Student1("张三",18));
        set.add(new Student1("李四",25));
        set.add(new Student1("王五",20));
        set.add(new Student1("赵六",20));
        for (Student1 student : set){
            System.out.println(student);
        }
    }
}
